#ifndef MONSTER_H
#define MONSTER_H

#include <vector>
#include "GlobalVariables.h"
#include "Movables.h"
#include "Utilities.h" //for delta and contains functions
#include <allegro5\allegro5.h>
#include "Point.h"
#include "Map.h"

using namespace std;

/*! \briefThis is a child class of Movables and contains the implementation for monsters

	The Monster class is complex in nature. It contains all routines related to the movement and collision detection of the monster object.
	Monster has a unique set of rules which govern his movement. These are implemented in the inherited collisionCheck function. 
	Unlike Dig Dug, Projectile and Rock monster determines its own movement. This requires knowlage of Dig Digs Position. 
	The self routing algorithm is contained within the Monster Object itself, whilst the Auto Routing path finding algorithm implemented as a stand alone function.

*/
class Monster: public Movables {
public:

	Monster(Point& location); //constructor
	Monster(){}

	//! \brief Contains implementation of move function defined in parent class, making use of rules specific to monsters's movement.
	virtual DetectionResult move(Map& map);


	virtual DetectionResult collisionCheck(Movable_type position_type) const;
	virtual void allowMove(Direction direction);

	//! \brief Sets the direction that the Monster must move in when commanded to move. 
	//! It gets the next direction from either the Auto Route list contined in _monster_route of from the Self Routing function
	void updateMoveDirection(Point& digdug_location, Map& map);

	//! \brief Takes in a point on the map and a map and returns a vector of directions in which a monster can move in
	//! This functino is used in both the Auto Routing and Self Routing functions 
	vector<Direction> getValidDirections(Point& location, Map& map);

	//! \brief Ghost mode is enabled whenever the monster is stuck within a tunnel with no path to Dig Dug for a given amount of time
	//! 
	void updateGhostMode(Point& digdug_location);
	
	//! \brief Returns true if the monster is in disembodied form set by _is_ghost
	bool isGhost();

	//! \brief Returns true if the monster has reached maximum blow up size as determined by _blow_up_size and _max_blow_up_size
	//! It increments the _blow_up_size counter
	bool blowUp();

	//! Sets the _monster_route variable with a path passed in by the Auto Route Function
	void setAutoRoute(vector <Point> route);

	//! Clears the _monster_route variable and is called priour to peforming the Auto Route Algorithm
	void clearRoute();

	//! Returns the _blow_up_size which is used in the draw function
	int blowUpSize();

	//! Returns the ghost bitmap, This differs from the Normal Bitmap that is inherited from movables. 
	ALLEGRO_BITMAP * ghostBitmap();
private:

//Datamembers of the class
	bool _is_ghost;
	Point _ghost_end_position;
	int _ghost_mode_counter;
	int _blow_up_size;
	int _max_blow_up_size;
	vector<Point> _monster_route;
	vector <Direction> _direction_list; //!< Used in self routing when ther is no path directily to digdug
	
//! \brief Private member functions to be used by Monster class.

	Point nextCoordinate();
	Direction selfRoute(Point& digdug_location, Map &map);
	void moveGhost();
		ALLEGRO_BITMAP * _ghost_bitmap;
};

//!Standalone Monster Routing
//void routeMonsters(Map &map, Point &digdug_position, vector<Monster> &monsters);
bool contains(vector <Point> point_list, Point point );
int monsterLocatedcheck(const vector<Point> route, vector<Monster> & monsters);
void routeMonsters(Map &map, Point &digdug_position, vector <Monster> & monsters );
#endif